home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / MacDOS 1.0.1 / batch files / trash.bat < prev    next >
Encoding:
DOS Batch File  |  1993-08-05  |  3.4 KB  |  117 lines  |  [TEXT/mDOS]

  1. @echo off
  2. !  trash.bat    Batch file to move files and folders to the trash bin
  3. !
  4. !  This program emulates the trashing of files and folders as done by the Mac
  5. !  when a user drags items to the Trash
  6. !  Just type:
  7. !      trash name
  8. !  where 'name' can be a file name (wildcarded or not) or a folder name
  9. !
  10. !  *** WARNING ***
  11. !  The Trash of the startup volume is used, regardless of whether the items to be
  12. !  trashed are on that volume or not.
  13. !
  14. !  Copyright © 1993 by Rainbow Hill Pty Ltd. All rights reserved.
  15. !
  16.  
  17.     echo Files and folders being copied:
  18.  
  19.     ! set up the handling of errors
  20.     onerror ERR_LBL
  21.  
  22.     ! first check whether the user has typed a parameter 
  23.     if not "%1 " == " " goto SYNTAX_DONE_LBL
  24.         echo No arguments. Type trash/? for help
  25.         goto DONE_LBL
  26.         :SYNTAX_DONE_LBL
  27.  
  28.     ! check whether help is requested
  29.     ! the space before /? is needed because the presence of a parameter equal to
  30.     ! /? overrides everything else. We would then get the IF's help !
  31.     if not " %1" == " /?" goto HELP_DONE_LBL
  32.         echo Trashes a file or a folder
  33.         echo.
  34.         echo    TRASH name
  35.         echo    name:    file[s] or folder to be trashed.
  36.         echo            Note that the name cannot contain a path.
  37.         echo.
  38.         goto DONE_LBL
  39.         :HELP_DONE_LBL
  40.  
  41.     ! check that the user has not typed more than one parameter
  42.     if "%2 " == " " goto SYNTAX1_DONE_LBL
  43.         echo Too many parameters. Type trash/? for help
  44.         goto DONE_LBL
  45.         :SYNTAX1_DONE_LBL
  46.  
  47.     ! check whether the user wants to copy a single file or a wildcarded
  48.     ! filename (EXIST ignores the folders). If so, fall through and do a
  49.     ! straight COPY.
  50.     if not exist %1 goto FOLDER_LBL
  51.         copy %1 1:\trash
  52.         del %1
  53.         goto DONE_LBL
  54.  
  55. :FOLDER_LBL
  56.     ! Either the item is a folder or does not exist at all.
  57.     ! Check whether it is a folder.
  58.     if existdir %1 goto FOLDER_OK_LBL
  59.         set doserr=27
  60.         goto ERR_LBL
  61.         :FOLDER_OK_LBL
  62.  
  63.     ! extract the folder name from the path
  64.     set foldername=%1
  65.     ! extract what follows the last backslash (if there is one)
  66.     onerror NO_SLASH_LBL
  67.     sstr foldername "\" /e /r
  68.     goto FOLDERNAME_DONE_LBL
  69. :NO_SLASH_LBL
  70.     ! if the error just says that there is no backslash, just fall through
  71.     if not %doserr% == 72 goto ERR_LBL
  72.         ! try to extract what follows the first colon (remember, there is no backslash)
  73.         onerror NO_COLON_LBL
  74.         sstr foldername ":" /r
  75.         goto FOLDERNAME_DONE_LBL
  76.     :NO_COLON_LBL
  77.         ! if the error just says that there is no colon, just fall through
  78.         if not %doserr% == 72 goto ERR_LBL
  79.  
  80. :FOLDERNAME_DONE_LBL
  81.     ! restore the standard error handling before doing anything else
  82.     onerror ERR_LBL
  83.  
  84.     ! check that the user does not want to delete a parent folder
  85.     if not %foldername% == .. goto FOLDERNAME_OK_LBL
  86.         echo Illegal path (it ends with a ".."). Type trash/? for help
  87.         goto DONE_LBL
  88.         :FOLDERNAME_OK_LBL
  89.  
  90.     ! create in the Trash a folder with the requested name
  91.     ! this is necessary because XCOPY does not copy the folder itself
  92.     onerror CREATE_ERR_LBL
  93. :CREATE_LBL
  94.     md 1:\trash\%foldername%
  95.     goto CREATE_DONE_LBL
  96. :CREATE_ERR_LBL
  97.     if not %doserr% == 58 goto ERR_LBL
  98.         incr foldername by $
  99.         goto CREATE_LBL
  100. :CREATE_DONE_LBL
  101.     onerror ERR_LBL
  102.  
  103.     ! XCOPY everything to the newly created folder
  104.     xcopy %1 1:\trash\%foldername% /s/e
  105.  
  106.     ! remove the temporary variables and delete the original folder
  107.     set foldername=
  108.     deldir "%1"
  109.     ! Note that control will never come back from DELDIR (it was not a CALL).
  110.     ! That is, we will not come back from the command deldir "%1"
  111.     !goto DONE_LBL
  112.  
  113. :ERR_LBL
  114.     show %doserr%
  115.  
  116. :DONE_LBL
  117.